<template>
  <div>
    <!-- 索赔结算发票查询 -->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="4" :collapse="collapse" labelWidth="110" @filterChange="changeHandle"></TopFilter>
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      selectionType="single"
    >
      <template slot="controls" slot-scope="props">
        <el-button size="small" type="primary"   @click="claimExportData">导出</el-button>
      </template>
    </FilterTable>

    <!-- 材料费发票明细页面 -->
    <Drawer :visible.sync="openPartSettleDetailPage" :title="dialogTitle" width="60%" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <partPageInfo @close="closePartSettleDetailPage" @save="save" :rowData="rowData" ></partPageInfo>
    </Drawer>

    <!-- 服务费发票明细页面 -->
    <Drawer :visible.sync="openServiceSettleDetailPage" :title="dialogTitle" width="60%" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <servicePageInfo @close="closeServiceSettleDetailPage" @save="save" :rowData="rowData" ></servicePageInfo>
    </Drawer>

  </div>
</template>
<script>
import moment from "moment";  
import partPageInfo from './partPageInfo.vue';
import servicePageInfo from './servicePageInfo.vue';
import { exportExcelFile } from '@/utils/index';
import { getAppId } from '@/assets/js/auth';
import { dictionary } from '@/utils/dictMixin';
import { queryPartInvoiceSearchInfo ,getPartType,exportSearchurl,auditInvoiceResult} from '@/api/claim/factory/claimStatamentInvoiceAudit';
import { troubleDesc } from '../../../../api/repair/precontract/precontractStatus';
// mock 方法 
//import mockFun from "@/mock/fun"
//const { mockList } = mockFun.ClaimStatementQueryDealer.mockFunWrap()// 涉及闭包 所以需要先调用外层函数一次 然后通过解构获取对应mock方法

export default {
  name:"claimStatementInvoiceQuery",
  mixins: [dictionary],
  components: {
    partPageInfo,
    servicePageInfo
  },
  data() {
    return {
      dataList: [],
      openPartSettleDetailPage: false,
      openServiceSettleDetailPage: false,
      visibleDrawer: false,
      collapse: true,
      infoId: null,
      fetchapi: queryPartInvoiceSearchInfo ,//getClaimAccountInfo,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      rowData: {},
      dataType:'',
      columns: this.creatHeader(),
      fetchParams: {xhrAbort: false}, //ipa 接口
      selectedRows: [], 
      dialogTitle: '结算信息详情',
      visibleAdd: false,
      signInvoices: false,
    };
  },
  created() {
    //this.chuqi();
  },
  methods: {
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      // if(this.selectedRows[0].orderStatus === 50051003){
      //   this.auditInvoices=false;
      //   this.signInvoices=true;
      //   this.checkInvoices=true;
      //   this.transferConfirms=true;
      // }else if(this.selectedRows[0].orderStatus === 50051005){
      //   this.auditInvoices=true;
      //   this.signInvoices=false;
      //   this.checkInvoices=true;
      //   this.transferConfirms=true;
      // }else if(this.selectedRows[0].orderStatus === 50051006){
      //   this.auditInvoices=true;
      //   this.signInvoices=true;
      //   this.checkInvoices=false;
      //   this.transferConfirms=true;
      // }else if(this.selectedRows[0].orderStatus === 50051007){
      //   this.auditInvoices=true;
      //   this.signInvoices=true;
      //   this.checkInvoices=true;
      //   this.transferConfirms=false;
      // }else{
      //   this.auditInvoices=true;
      //   this.signInvoices=true;
      //   this.checkInvoices=true;
      //   this.transferConfirms=true;
      // }


      console.log(this.selectedRows);
    },

    

    closePartSettleDetailPage() {
      this.openPartSettleDetailPage = false;
    },
    closeServiceSettleDetailPage(){
        this.openServiceSettleDetailPage = false;
    },
   
    closeDialogPage(){
      this.openDialogPage = false;
    },
    chooseOrderNo(val) {
      this.rowData = val;
      console.log("2222",this.rowData)
      this.dialogTitle="索赔结算发票明细";
      if(this.rowData.finalStatementType === 50021002){// 材料费
        this.openPartSettleDetailPage = true;
      }else if(this.rowData.finalStatementType === 50021001){// 服务费
        this.openServiceSettleDetailPage = true;
      }
    },
   
    
    save() {
      this.visible = false;
      this.fetchParams = { ...this.fetchParams };
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val,{xhrAbort: false});
      console.log(val);
    },
    // 索赔结算单导出
    async claimExportData() {
      await exportSearchurl(this.fetchParams).then(res => {
        console.log(res);
        exportExcelFile(res.data, '索赔结算发票查询导出');
      });
    },
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: '服务中心代码', fieldName: 'dealerCode', placeholder: '请输入服务站代码...', initialValue: '' },
        { type: 'INPUT', label: '服务中心简称', fieldName: 'dealerName', placeholder: '请输入服务站简称...', initialValue: '' },
        { type: 'INPUT', label: '结算单号', fieldName: 'settleNo', placeholder: '请输入结算单号...', initialValue: '' },
        { type: 'INPUT', label: '结算月份', fieldName: 'settleDate', placeholder: '请输入索赔月份...', initialValue: '' },
        { type: 'SELECT', label: '发票状态', fieldName: 'orderStatus', placeholder: '请选择发票状态...', initialValue: '', itemList: [{value:50051001,text:"待开票"},{value:50051002,text:"待签收"},
        {value:50051003,text:"已签收"},{value:50051004,text:"财务驳回"},{value:50051005,text:"已转款"}]},
        
        // { type: 'SELECT', label: '索赔车辆属性', fieldName: 'carType', placeholder: '请选择索赔车辆属性...', initialValue: '',itemList: this.createDlrDictList('5543') }
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          fixed: 'left',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.chooseOrderNo(props.row)}>
                  明细
                </multiuse-button>
              </div>
            );
          }
        },  
        { title: '服务中心代码', dataIndex: 'dealerCode', sorter: true },
        { title: '服务中心简称', dataIndex: 'dealerName', sorter: true },                       
        { title: '发票状态', dataIndex: 'orderStatus', sorter: true, showOverflowTooltip: true, dictItems: this.createDictList('5005')},
        { title: '结算单号', dataIndex: 'settleNo', sorter: true },
        { title: '结算月份', dataIndex: 'settleDate', sorter: true },
        { title: '结算单类型', dataIndex: 'finalStatementType', dictItems: this.createDictList('5002')},
        { title: '结算金额', dataIndex: 'settleAmount', sorter: true,precision: 2 },
        // { title: '结算单类型', dataIndex: 'finalStatementType', sorter: true },
       { title: '发票类别', dataIndex: 'orderType', dictItems: this.createDictList('5010')},
        { title: '结算比例', dataIndex: 'settleRate', sorter: true },
        { title: '开票金额', dataIndex: 'invoiceAmount', sorter: true ,precision: 2},
        { title: '发票张数', dataIndex: 'invoiceNum', sorter: true },
        { title: '更新时间', dataIndex: 'updateDate', sorter: true },
        
      ];
    }
  }
};
</script>

<style lang="less" scoped></style>
